#include "ParticleSignalKey.h"

#include "ParticleContext.h"
#include "DescriptorParticle.h"

#include <StatusComponent.h>

using namespace ParticleEngine; 

const DescriptorParticle ParticleSignalKey::Descriptor
(
	"SignalKey", 
	[](ParticleContext& NewContext) { return new ParticleSignalKey(NewContext); }
); 

ParticleSignalKey::ParticleSignalKey(ParticleContext& NewContext) :
ParticleBase(NewContext, &ParticleSignalKey::Descriptor),
PropertyAdhesions(0.15f),
Heat(0.5f),
KeyCode(NewContext.Status.KeyboardLastCode)
{
	this->Adhesions = dynamic_cast<PropertyAdhesions*>(this);
	this->Adhesions->ParticleCast = dynamic_cast<ParticleBase*>(this);
}
ParticleSignalKey::~ParticleSignalKey()
{
}

void ParticleSignalKey::Sole()//einzelne aktualisierzung
{
	this->SoleStandard();

	if (Context.Status.KeyboardIsPressed[this->KeyCode] == true)
	{
		this->Signal0.Current = SignalStatus::Inactive;
		this->Signal1.Current = SignalStatus::Active;
	}
	else
	{
		this->Signal0.Current = SignalStatus::Active;
		this->Signal1.Current = SignalStatus::Inactive;
	}

	this->Heat.Sole();
	//this->Signal0.Sole();
	//this->Signal1.Sole();
}
void ParticleSignalKey::InteractionIndividual(ParticleBase*const Other, Vec<2, float>& Space, const float& DistanceSquared)
{
	this->InteractionKinetics(Other, Space, DistanceSquared);

	this->Heat.Interaction(Other->HasHeat());

	this->Signal0.Interaction(Other->HasSignal0());
	this->Signal1.Interaction(Other->HasSignal1());
}
ColorRGBA<unsigned char> ParticleSignalKey::GetColor()
{
	if (Signal0.Current == SignalStatus::Active)
		return ColorRGBA<unsigned char> (255, 50, 50, 255);
	else
		return ColorRGBA<unsigned char> (50, 255, 50, 255);
}

void ParticleSignalKey::SaveIndividual(std::ofstream& Strm)
{
	Heat.Save(Strm);
	Signal0.Save(Strm);
	Signal1.Save(Strm);
	FileAccess::WriteByRef(Strm, this->KeyCode);
}
void ParticleSignalKey::LoadIndividual(std::ifstream& Strm)
{
	Heat.Load(Strm);
	Signal0.Load(Strm);
	Signal1.Load(Strm);
	FileAccess::ReadByRef(Strm, this->KeyCode);
}


